<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取到一个div里面的鼠标坐标.html</title>
    <style>
        #box1{
            width: 300px;
            height: 200px;
            border: 1px solid black;
        }
        #box2{
            margin-top: 30px;
            width: 300px;
            height: 100px;
            border: 1px solid black;
        }
    </style>
    <script type="text/javascript">
        window.onload = function () {
            let box1 = document.getElementById("box1");
            let box2 = document.getElementById("box2");
            box1.onmousemove = function (event) {
                event = event || window.event;
                let x = event.clientX;
                let y = event.clientY;
                box2.innerHTML = "x="+x+"  y="+y;
            }
        }
    </script>
</head>
<body>
    <div id="box1"></div>
    <div id="box2"></div>
</body>
</html>